{% extends 'blog/base.html' %}
{% load blog_tags %}
{% block title %}Search{% endblock title %}
{% block content %}
{% if query %}
 <!-- 如果有搜索内容显示搜索结果信息 -->
  <h1>Posts containing "{{ query }}"</h1>
  <h3>
 <!-- 显示总共搜到了多少篇相关文章 -->
    {% with results.count as total_results %}
      Found {{ total_results }} result{{ total_results|pluralize}}
    {% endwith %}
  </h3>
 <!-- 列出每一篇相关文章的标签和链接 -->
{% for post in results %}
  <h4><a href="{{ post.get_absolute_url }}">{{post.title}}</a></h4>
{% empty %}
  <p>There are no results for your query.</p>
{% endfor %}
 <!-- 结果不符合预期时可以重新搜索 -->
  <p><a href="{% url 'blog:post_search' %}">Search again</a></p>
{% else %}
 <!-- 如果没有搜索内容，显示搜索框 -->
  <h1>Search for posts</h1>
  <form method="get">
    {{ form.as_p }}
    <input type="submit" value="Search">
  </form>
{% endif %}
{% endblock content %}